package top.ucat.boots.common.check;

import org.apache.commons.lang3.StringUtils;
import top.ucat.boots.common.exception.BaseException;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;

/**
 * @Auther: Jun
 * @Date: 2019/9/3 18:53
 * @Description: 断言判断
 */
public class Assert {

    private final static List emptyList = new ArrayList();

    public static void isNotNull(Object obj, String message) {
        Assert.isNotNull(obj, message, 500);
    }

    public static void isNotNull(Object obj, String message, int status) {
        if (obj == null) {
            throw new BaseException(message, status);
        }
    }

    public static void isNotEmpty(String string, String message, int status) {
        if (StringUtils.isEmpty(string)) {
            throw new BaseException(message, status);
        }
    }

    /**
     * id集合为空,返回空集合,不然返回
     *
     * @param ids
     * @return
     */
    public static List arrIsNotEmpty(List ids, Function<List, List> fn) {
        if (ids != null && ids.size() > 0) {
            return fn.apply(ids);
        }
        return emptyList;
    }

}
